<script type="text/javascript"><!--//--><![CDATA[//><!--
 var LOVTenantTP = function(ao_option){
	try{
		if(ao_option==undefined){ ao_option={}; }
		var lf_onSelect	= (ao_option.onSelect==undefined || typeof(ao_option.onSelect)!='function') ? function(){} : ao_option.onSelect;
		
		// Create Popup
		var $popup	= openPopup({ title:'Daftar Tenant' , width:700, height:370 });
		var ls_id	= $popup.attr('id');
		
		// Append Datagrid Container
		var ls_gridName	= 'grid_'+ls_id;
		$popup	.html(	$('<div>')	.attr('id', 'tb'+ls_id).attr('style','padding:5px;height:auto;')
									.html(	$('<div>').html($('<form>')	.attr('id','fm_search_'+ls_id).data('rel',ls_id).submit(function(e){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).data('rel')).serializeObject()); e.preventDefault(); })
																		.html('<table class="tb_form" style="margin-bottom:0px"><tr><td width="100">Keyword</td><td><input type="text" name="keyword" class="textfield medium" /><a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search'+ls_id+'" rel="'+ls_id+'">Search</a></td></tr></table>')
															)
											)
						)
				.append($('<div>').attr('id', ls_gridName).attr('toolbar', '#tb'+$popup.attr('id')));
		
		$('#btn_search'+ls_id).click(function(){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).attr('rel')).serializeObject()); return false; });
		$('#btn_search'+ls_id).linkbutton({  
			plain:true  
		}); 
		
		// Build Datagrid
		var ls_param = (ao_option.param==undefined ? '' : ao_option.param);
		$('#'+ls_gridName).datagrid({  
			url:gs_path+'/pro_tenant/getdata/'+ls_param,
			queryParams: $('#fm_search_'+ls_id).serializeObject(),
			height:337,
			pagination:true,
			singleSelect:true,
			columns:[[
				{ field : 'nama_tenant', title : 'Nama Tenant', width : 100, sortable:true },
				{ field : 'no_tenant', title : 'No Tenant', width : 300, sortable:true },
				{ field : 'jenis_usaha', title : 'Jenis Usaha', width : 300, sortable:true },
				{ field : 'lokasi_tempat', title : 'Lokasi Tempat', width : 300, sortable:true },
				{ field : 'alamat_lengkap', title : 'Alamat Lengkap', width : 300, sortable:true }
			]],
			onSelect:function(rowIndex, rowData){ lf_onSelect(rowData); closePopup(); }
		});
		
	} catch (err) { alert('Func. LOVSampleReference :\n' + err); }
};
    $(document).ready(function() {
    	
    	 //Setup Form
		$('#form_master').setupForm([			
			{ name: 'id_tagihan_tlp', type: 'text', size: 'medium', maxlength: 255 },
			{ name: 'no_tagihan_tlp', type: 'text', size: 'medium', maxlength: 255 },
			{ name: 'nama_tenant', type: 'lov', size: 'long',
				onClearButton:function(){
					$(this).setval('');
					$(this).setval('');
				},
				onActionButton:function(){ 
					LOVTenantTP({ onSelect:function(row){ 
						$('#nama_tenant').setval(row.nama_tenant);
						$('#alamat').setval(row.alamat_lengkap); 
					} }); 
				}
			},
			{ name: 'atas_nama', type: 'text', size: 'long', maxlength: 255 },
			{ name: 'alamat', type: 'text', size: 'long', maxlength: 255 },
			{ name: 'bulan', type: 'text', size: 'short', maxlength: 15 },
			{ name: 'tahun', type: 'text', size: 'short', maxlength: 15 },
			{ name: 'tanggal_bayar', type: 'date', size: 'short', maxlength: 30 }
		], <?php echo json_encode($data); ?>);
		
		// Set Action Button
		var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
							$('#form_master').submitForm(	'/'+controller+'/ajax_post', 
							{ detail:[	{ table: 'dtl_sample2', field:['id_tagihan_tlp','id_tagihan_tlp_dtl','keterangan_tagihan','biaya_tagihan','biaya_adm_bank']}], 
							//onComplete : function(data){ eval('oData = '+data); loadPage('/'+controller+'/edit/?kode_penjualan='+(oData.genid!='' ? oData.genid : $('#kode_penjualan').getval())); }
							onComplete : function(data){ eval('oData = '+data); loadPage('/'+controller+'/index'); }
							}); 
						}},
					   { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/index'); } }];
		setAction(buttons);
		
		// Create Tab
		$('#tt').tabs({ border:false }); 

		// Focus at First Object
		$('#form_master').focusFirst();
		
		<?php
			if ($mode == 'edit') {
				?>
					var id_tagihan_tlp_auto = "<?php echo $id_tagihan_tlp_auto; ?>";
					$('#id_tagihan_tlp').readonly();

					var bulan = '<?php echo $bulan ; ?>'
		            var tahun = '<?php echo $tahun ; ?>'

		            $('#bulan').setval(bulan);
		            $('#tahun').setval(tahun);
				<?php
			}
			
		?>

		<?php
			if ($mode == 'create') {
				?>
					var no_tagihan_tlp_auto = "<?php echo $no_tagihan_tlp_auto; ?>";
					var id_tagihan_tlp_auto = "<?php echo $id_tagihan_tlp_auto; ?>";
					
					$('#id_tagihan_tlp').setval(id_tagihan_tlp_auto);
					$('#no_tagihan_tlp').setval(no_tagihan_tlp_auto);
				<?php
			}
			
		?>

		});
//--><!]]></script>
	
<div id="form_master_message" style="display:none;"></div>
<table class="tb_form" style="display:none;" cellpadding="0" cellspacing="0">
	 <tr>
        <td class="label">ID tagihan</td>
        <td><input id="id_tagihan_tlp" /></td>
    </tr>
    <tr>
        <td class="label">Nomor tagihan</td>
        <td><input id="no_tagihan_tlp" /></td>
    </tr>
    <tr>
        <td class="label">Nama Tenant</td>
        <td><input id="nama_tenant" /></td>
    </tr>
    <tr>
        <td class="label">Alamat Rumah/Kantor</td>
        <td><input id="alamat" /></td>
    </tr>
    <tr>
        <td class="label">Atas Nama</td>
        <td><input id="atas_nama" /></td>
    </tr>
    <tr>
        <td class="label">Tanggal Bayar</td>
        <td><input id="tanggal_bayar" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Periode Tagihan</td>
        <td ><select id="bulan" name="bulan">
                <option value="Januari">Januari</option>
                <option value="Februari">Februari</option>
                <option value="Maret">Maret</option>
                <option value="April">April</option>
                <option value="Mei">Mei</option>
                <option value="Juni">Juni</option>
                <option value="Juli">Juli</option>
                <option value="Agustus">Agustus</option>
                <option value="September">September</option>
                <option value="Oktober">Oktober</option>
                <option value="November">November</option>
                <option value="Desember">Desember</option>
            </select>
            <?php
            $now = date('Y');
            $pastYear = $now - 10; 
        	echo "<select id='tahun' name='tahun' >";
        		for ($a=$pastYear;$a<=$now;$a++)
        		{
        			echo"<option value='".$a."''>".$a."</option>";	
        		}
        		 echo"</select>";
        	?>
        </td>
    </tr>
</table>
<div id="tt" class="easyui-tabs" style="min-height:400px;"> 
	<div title="Detail" style="overflow:auto;padding:10px;">  
    	<?php require_once('formdtl.php'); ?>
    </div>
    
</div>